<main class="lyear-layout-content">

    <div class="container-fluid p-t-15">

        <div class="row">
            <div class="col-lg-6">
                <div class="card">
                    <div class="card-header">
                        <h4>采纳状态</h4>
                    </div>
                    <div class="card-body">
                        <canvas id="chart-bars"></canvas>
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="card">
                    <div class="card-header">
                        <h4>帖子数据</h4>
                    </div>
                    <div class="card-body">
                        <canvas id="chart-line"></canvas>
                    </div>
                </div>
            </div>
        </div>

    </div>

</main>

<script type="text/javascript" src="/static/admin/js/Chart.min.js"></script>

<script>
    $.ajax({
        type: "post",
        url: `{:url('admin/analysis/post')}`,
        data: {
            action: 'accept'
        },
        dataType: "json",
        success: function (res) {
            if (res.code === 1) {
                var name = res.data.name
                // 采纳
                var Accept = res.data.Accept
                // 未采纳
                var NoAccept = res.data.NoAccept

                new Chart($("#chart-bars"), {
                    type: 'bar',
                    data: {
                        labels: name,
                        datasets: [{
                            label: "采纳",
                            borderColor: "#36a2eb",
                            backgroundColor: "#36a2eb",
                            data: Accept,  //X轴对应的值
                        },
                        {
                            label: "未采纳",
                            borderColor: "#ff6384",
                            backgroundColor: "#ff6384",
                            data: NoAccept //X轴对应的值
                        }]
                    },
                });
            }
        }
    });
    $.ajax({
        type: "post",
        url: `{:url('admin/analysis/post')}`,
        data: {
            action: 'visit'
        },
        dataType: "json",
        success: function (res) {
            if (res.code === 1) {
                // X轴名字
                var name = res.data.name
                // 浏览量
                var visit = res.data.visit
                var comment = res.data.comment
                new Chart($("#chart-line"), {
                    type: 'bar',
                    data: {
                        labels: name,
                        datasets: [{
                            label: "浏览量",
                            borderColor: "#36a2eb",
                            backgroundColor: "#36a2eb",
                            data: visit,  //X轴对应的值
                        },
                        {
                            label: "评论量",
                            borderColor: "#ff6384",
                            backgroundColor: "#ff6384",
                            data: comment,  //X轴对应的值
                        }
                    ]
                    }
                });
            }
        }
    });
</script>